package com.example.onlinemonitoring.serviceImpl;

import com.example.onlinemonitoring.model.Yggxsensor;
import com.example.onlinemonitoring.model.Oilsensor;
import com.example.onlinemonitoring.model.Yggxhistory;
import org.springframework.stereotype.Service;
import com.example.onlinemonitoring.Util.tem.SensorAbstractBaseService;
import com.example.onlinemonitoring.service.YggxsensorService;
import com.example.onlinemonitoring.model.common.chartres;
import com.example.onlinemonitoring.Util.HexUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
* @description Yggxsensor接口实现
* @author  generator
* @since  2022-04-09 13:03:09
*/
@Service("yggxServiceImpl")
public class YggxsensorServiceImpl extends SensorAbstractBaseService<Yggxsensor, Yggxhistory> implements YggxsensorService {
     //这里需要重写getDt方法,用来处理图表数据
    //public String[] getDt(List<Yggxhistory> list,String[] dt,chartres cts,float[][] sres,SimpleDateFormat sdf,SimpleDateFormat csdf,SimpleDateFormat sdf2){return null;}
        public void UpdateStyle(String style) {
        List<Yggxsensor> list = selectAll();
        if (list.size() <= 0) {
            return;
        }
        String old_style = list.get(0).getStyle();
        StringBuilder newStyleBuilder = new StringBuilder();
        String[] parts = style.split(",");
        String[] oldParts = old_style.split(",");
        for (int i = 0; i < parts.length; i++) {
            String[] newkeyValue = parts[i].split("\\|");
            String[] oldkeyValue = oldParts[i].split("\\|");

            newStyleBuilder.append(oldkeyValue[0] + "|" + oldkeyValue[1] + "|" + newkeyValue[2]);
            newStyleBuilder.append(",");
        }

        // 移除最后一个逗号
        if (newStyleBuilder.charAt(newStyleBuilder.length() - 1) == ',') {
            newStyleBuilder.setLength(newStyleBuilder.length() - 1);
        }
        Yggxsensor record = new Yggxsensor();
        record.setStyle(newStyleBuilder.toString());
        Update(record, false);
    }
}
